from logging import getLogger
from random import randint

from celery_tasks.main import celery_app
from meiduo.utils.ronglian_sms_sdk.SendMessage import send_message

logger = getLogger('django')


@celery_app.task(name='send_sms_code')
def send_sms_code(mobile, sms_code, time):

    res = send_message('1', mobile, (sms_code, time))

    if res == '000000':
        logger.info("[手机号: %s][验证码：%s][有效期：%s] 发送短信验证码[成功]" % (mobile, sms_code, time))
    else:
        logger.error("[手机号: %s][验证码：%s][有效期：%s] 发送短信验证码[失败]" % (mobile, sms_code, time))

    return res

